package com.zw.web.validation.common.result;

import lombok.Data;

@Data
public class ResponseResult<T> {
    private int code;
    private String msg;
    private T data;

    public static <T> ResponseResult<T> success(T data) {
        return success(ResultStatus.SUCCESS, data);
    }

    public static <T> ResponseResult<T> success(ResultStatus resultStatus, T data) {
        return common(resultStatus, data);
    }

    public static <T> ResponseResult<T> error(ResultStatus resultStatus) {
        return common(resultStatus, null);
    }


    public static <T> ResponseResult<T> error(ResultStatus resultStatus, T errorData) {
        return common(resultStatus, errorData);
    }

    public static <T> ResponseResult<T> error() {
        return error(ResultStatus.SYS_ERROR);
    }

    public static <T> ResponseResult<T> noBrandError() {
        return error(ResultStatus.USER_NO_EXIST);
    }

    public static <T> ResponseResult<T> beenDeleteError() {
        return error(ResultStatus.USER_BEEN_DELETE);
    }

    public static <T> ResponseResult<T> brandExistError() {
        return error(ResultStatus.USER_EXIST_ERROR);
    }

    private static <T> ResponseResult<T> common(ResultStatus resultStatus, T data) {
        ResponseResult<T> result = new ResponseResult<T>();
        result.setCode(resultStatus.getCode());
        result.setMsg(resultStatus.getMsg());
        result.setData(data);
        return result;
    }
}
